package com.qf.tenement.tenement_rent.service.impl;

import com.qf.tenement.tenement_entity.ResultData;
import com.qf.tenement.tenement_rent.Renting;
import com.qf.tenement.tenement_rent.dao.RentDao;
import com.qf.tenement.tenement_rent.service.RentService;
import com.qf.tenement.tenement_utils.MessageCodeConstants;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RentServiceImpl implements RentService {
    @Resource
    private RentDao rentDao;
    @Override
    public ResultData selectAll() {
        List<Renting> rentings = rentDao.selectList(null);
        if (rentings == null || rentings.size() == 0){
            return ResultData.createFailJsonResult(MessageCodeConstants.RENT_LIST_NOTALL,"查询失败");
        }
        return ResultData.createSuccessJsonResult(rentings);
    }

    @Override
    public ResultData rentAdd(Renting renting) {
        if (rentDao.insert(renting) == 0){
            return ResultData.createFailJsonResult(MessageCodeConstants.RENT_ADD_NOT,"添加失败");
        }
        return ResultData.createSuccessJsonResult("添加成功");
    }

    @Override
    public ResultData rentDelect(String roomId) {
        if (rentDao.deleteById(roomId) == 0){
            return ResultData.createFailJsonResult(MessageCodeConstants.RENT_DELECT_NOT,"删除失败");
        }
        return ResultData.createSuccessJsonResult("删除成功");
    }


}
